class Solution(object):
    def isValid(self, s):

        #近的匹配在一起，所以是先进来的后出去  所以是栈
        """
        :type s: str
        :rtype: bool
        """
        leftP = '([{'
        rightP = ')]}'

        stack = []
        for char in s:
            if char in leftP:
                stack.append(char)
            if char in rightP:
                if len(stack) == 0:
                    return False
                tmp = stack.pop()
                if char == ')' and tmp != '(':
                    return False
                if char == ']' and tmp != '[':
                    return False
                if char == '}' and tmp != '{':
                    return False
        return stack == []